package com.zbf.web;

import com.zbf.config.TestManger;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author: LCG
 * @Date: 2021-11-14 15:40:58
 * @description:
 **/
@RestController
public class TestController {

    @RequestMapping("test1/{taskName}")
    public void test1(@PathVariable String taskName){
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        scheduledThreadPoolExecutor.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("===============");
            }
        },10000,1000, TimeUnit.MILLISECONDS);
        TestManger.taskManger.put(taskName,scheduledThreadPoolExecutor);
    }


    @RequestMapping("update/{taskName}")
    public void update(@PathVariable String taskName){
        ScheduledExecutorService scheduledExecutorService = TestManger.taskManger.get("15");
        scheduledExecutorService.shutdown();

        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        scheduledThreadPoolExecutor.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("========5=======");
            }
        },10000,5000, TimeUnit.MILLISECONDS);
        TestManger.taskManger.put(taskName,scheduledThreadPoolExecutor);
    }


}
